import{ Observable }from'rxjs/Observable';
import {Injectable} from '@angular/core';
import'rxjs/add/observable/of';

import {ResponseList,ModulePermission,ResponseBody,ModuleTree,Permission,UserParams,User} from "../entities/entities"
import {LocalStorage,Http} from "../utils/utils";
import {Router} from "@angular/router"
@Injectable()
export class UserService{
	constructor(private router:Router,private http:Http){
	}
	/** 根据条件查询 user*/
	selectFromUser(userParams:UserParams):Promise<ResponseList<User>>{
		return this.http.request({
			url:`user/list/${userParams.pageSize}/${userParams.pageNum}`,
			data:userParams
		})/*.then((json:any)=>{
			var users:User[]=(json["items"]||[]).map((e:any)=>{
				var roleNames:string[]=(e["roleNames"]||[]).map((s:any)=>{
					return String(s);
				});
				return new User(
					String(e["account"]),
					String(e["password"]),
					String(e["name"]),
					roleNames,
					String(e["createUserName"]),
					e["createTime"],
					String(e["lastUpdateUserName"]),
					e["lastUpdateTime"],
					String(e["note"]),
					!!e["active"]);
			});
			return new ResponseList<User>(
				parseInt(json["pages"]),
				parseInt(json["total"]),
				users
			);
		})*/;
	}
	/**通过 accounts 批量删除 user*/
	deleteUserByAccounts(accounts:string[]):Promise<any>{
		return this.http.request({
			url:`user/delete`,
			data:accounts
		});
	}
	/**批量修改 user状态*/
	updateUserByIds(userIds:number[],user:User){
		return this.http.request({
			url:`user/update`,
			data:{
				userIds:userIds,
				user:user
			}
		});
	}
	/**根据 用户 ids 查询 用户 id name*/
	selectIdNameFromUserByIds(userIds:number[]):Promise<User[]>{
		return this.http.request({
			url:`user/select/IdNameByIds`,
			data:userIds
		});
	}
	/**新增用户*/
	insert(user:User):Promise<any>{
		return this.http.request({
			url:`user/insert`,
			data:user
		});
	}
}
